﻿using System.Windows;
using System.Windows.Input;
using MadMediaManager.WPFSupport.Interfaces.ViewModels;
using MadMediaManager.WPFSupport.Interfaces.Views;

namespace MadMediaManager.Views.Shell
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : IMainView, IContentRegionOwner
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
            }
            else
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    DragMove();
                }
            }
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            if (ViewModel == null) return;
            ViewModel.Dispose();
            ViewModel = null;
        }

        public IViewModel ViewModel
        {
            get { return DataContext as IViewModel; }
            set { DataContext = value; }
        }

        public void AddView(INavigableView view)
        {
            ContentRegion.Children.Add((UIElement)view);
        }

        public void RemoveView(INavigableView view)
        {
            ContentRegion.Children.Remove(view as UIElement);
        }
    }
}
